<template>
	<view class="container bg-grey">
		<sb-loading-container ref='loadingRef'>
			<view class="padv20">
				<scroll-view scroll-x>
					<view class="flex flex-nowrap">
						<view v-for="(item, index) in typeList" :key="item.id" class="mar10 flex flex-col j-a-c"
							@click="$go2(`/pages/article/list-cate?typeId=${item.id}&type=${item.name}`)">
							<sb-img w="100" r='100' shadow mode='center' :src="$getStaticUrl(item.cover)" />
							<u-gap height="10"></u-gap>
							<view class="t-c">{{item.name}}</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="flex j-s padh20">
				<navigator v-for="(item, i) in articleList" :key="index" :url="`/pages/article/detail?id=${item.id}`"
					class="marv15 pad10 radius10 bg-white relative">
					<view class="no absolute top0 left0 c-w flex j-a-c font24">{{i+1}}</view>
					<view style="text-indent: 40rpx;line-height: 40rpx;">
						<u-parse :html='limitStr(item.content,70)' />
					</view>
				</navigator>
			</view>
		</sb-loading-container>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				banners: [],
				typeList: [],
				articleList: [],
				qs: {
					page: 1,
					size: 20,
				}
			};
		},
		onShareAppMessage() {

		},
		onShareTimeline() {

		},
		onPullDownRefresh() {
			setTimeout(() => uni.stopPullDownRefresh(), 500)
			this.qs.page = 1
			this.articleList = []
			this.$nextTick(() => this.getList())
		},
		onLoad({ pid }) {
			this.pid = pid
			this.getTypeList()
			this.getList();
		},
		onReachBottom() {
			this.qs.page++
			this.getList()
		},
		methods: {
			async getList() {
				try {
					this.$refs.loadingRef.show()
					let { success, data } = await this.$get("/article", this.qs, false);
					if (success) {
						this.articleList = this.articleList.concat(data.rows)
					}
				} finally {
					this.$refs.loadingRef.hide()
				}

			},
			async getTypeList() {
				let { success, data } = await this.$get("/type", { pid: this.pid }, false);
				if (success) {
					this.typeList = data
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.container {
		/deep/ {
			.u-tabbar__content {
				position: absolute;
			}

			.u-sticky {
				background-color: #fff;
			}
		}
	}

	.no {
		background-color: rgba($color: #009966, $alpha: 0.7);
		width: 40rpx;
		height: 40rpx;
	}
</style>
